package com.leap.controller;

import com.leap.entity.RestBean;
import com.leap.entity.dto.MediaUploadDTO;
import com.leap.utils.UploadUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.http.MediaTypeFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import ws.schild.jave.EncoderException;
import ws.schild.jave.MultimediaObject;
import ws.schild.jave.info.MultimediaInfo;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.UUID;

@RestController
@RequestMapping("/api/common")
@Slf4j
@Tag(name = "资源上传下载接口服务")
public class CommonController {

    /**
     * 图片上传
     * @param file
     * @return
     */
    @Operation(summary = "照片上传接口")
    @PostMapping("/imgUpload")
    public RestBean<String> imgUpload(MultipartFile file) throws IOException {

        String imgeUrl = UploadUtil.ImgUpload(file);

        return RestBean.success(imgeUrl);
    }


    /**
     * 图片上传
     * @param file
     * @return
     */
    @Operation(summary = "视频上传接口")
    @PostMapping("/videoUpload")
    public RestBean<MediaUploadDTO> videoUpload(MultipartFile file) throws EncoderException, IOException {

        MediaUploadDTO mediaUploadDTO = UploadUtil.VideoUpload(file);

        return RestBean.success(mediaUploadDTO);
    }


}
